<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
			label-width="68px">
			<el-form-item label="记录名称" prop="recordName">
				<el-input v-model="queryParams.recordName" placeholder="请输入记录名称" clearable maxlength="20"
					show-word-limit @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
					v-hasPermi="['system:package:add']">新增</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
					v-hasPermi="['system:package:remove']">删除</el-button>
			</el-col>
			<CreateForm :ids="ids" formtype="t_packRecords" />
			<right-toolbar menuNames="coutsource74" @changeTableData="changeTableData" :columns.sync="columns"
				:showSearch.sync="showSearch" @queryTable="getList"
				perm="packageRecords:packageRecords:list"></right-toolbar>
		</el-row>

		<div :class="sidebar.opened && eleTabTop <= 85 ? 'eleTab' : !sidebar.opened && eleTabTop <= 85 ? 'eleTabs' : ''"
			class="informationTab" ref="eleTab">
			<el-table ref="table" @mousedown.native="mousedownTables" @cell-mouse-enter="cell_mouse_enters" row-key="id"
				@cell-mouse-leave="cell_mouse_leaves" @mouseup.native="mouseupTables" @mouseleave.native="mouseupTables"
				@row-click="row_click" v-loading="loading" :data="configList" @selection-change="handleSelectionChange"
				border height="100%">
				<el-table-column type="selection" width="55" align="center" />
				<el-table-column type="index" width="55" align="center" label="序号" />
				<el-table-column label="记录名称" prop="recordName" :show-overflow-tooltip="true" min-width="150"
					v-if="columns[0].visible" />
				<el-table-column label="产品名称" prop="productName" :show-overflow-tooltip="true" min-width="150"
					v-if="columns[1].visible" />
				<el-table-column label="产品编号" prop="productNumber" :show-overflow-tooltip="true" min-width="150"
					v-if="columns[2].visible" />
				<el-table-column label="产品型号" prop="productModel" :show-overflow-tooltip="true" min-width="150"
					v-if="columns[3].visible" />
				<el-table-column label="包装发货状态" prop="packagDeliverStatus" :show-overflow-tooltip="true" min-width="150"
					align="center" v-if="columns[4].visible">
					<template slot-scope="scope">
						<div v-if="scope.row.packagDeliverStatus == '1'">未发货</div>
						<div v-else>已发货</div>
					</template>
				</el-table-column>
				<el-table-column label="备注" prop="remark" :show-overflow-tooltip="true" min-width="150"
					v-if="columns[5].visible" />
				<el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right"
					width="280">
					<template slot-scope="scope">
						<!--  v-if="scope.row.informantStatus == '0'"  -->
						<el-button size="mini" type="text" icon="el-icon-edit" @click="handleWrite(scope.row)"
							v-hasPermi="['system:package:write']" v-if="scope.row.informantStatus == 0">填写</el-button>
						<el-button v-if="scope.row.verificationStatus == '0'" size="mini" type="text"
							icon="el-icon-check" @click="handleReocrds(scope.row)"
							v-hasPermi="['system:package:record']">核验</el-button>
						<!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleChecked(scope.row)" v-hasPermi="['system:package:checked']">发货检查</el-button> -->
						<el-button size="mini" type="text" icon="el-icon-view" @click="handleReocrds1(scope.row)"
							v-hasPermi="['system:package:details']">详情</el-button>
						<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
							v-hasPermi="['system:package:edit']" v-if="scope.row.informantStatus == 1">修改</el-button>
						<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
							v-hasPermi="['system:package:remove']">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
		</div>

		<pagination menuNames="Pagination25" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
			:limit.sync="queryParams.pageSize" @pagination="getList" />

		<!-- 添加或修改参数配置对话框 -->
		<el-dialog title="添加包装产品" :visible.sync="open" width="1500px" append-to-body v-dialogDrag>
			<div class="userDialog">
				<div class="userLeft">
					<el-form :model="queryProcuct" ref="queryProcuct" size="small" :inline="true">
						<el-form-item label="产品型号" prop="productModel">
							<el-input clearable style="width: 200px" v-model="queryProcuct.productModel"
								placeholder="请输入产品型号" maxlength="20" show-word-limit />
						</el-form-item>
						<el-form-item label="产品编号" prop="productNumber">
							<el-input clearable style="width: 200px" v-model="queryProcuct.productNumber"
								placeholder="请输入产品编号" maxlength="20" show-word-limit />
						</el-form-item>
						<el-form-item>
							<el-button type="primary" icon="el-icon-search" size="mini"
								@click="handleQueryUser">搜索</el-button>
							<el-button icon="el-icon-refresh" size="mini" @click="resetQueryUser">重置</el-button>
						</el-form-item>
					</el-form>
					<el-table height="488px" v-loading="productloading" :data="productList"
						@selection-change="handleSelectionProduct" ref="multipleTable">
						<el-table-column type="selection" width="55" align="center" />
						<el-table-column type="index" width="55" align="center" label="序号" />
						<el-table-column label="产品名称" prop="productName" :show-overflow-tooltip="true" />
						<el-table-column label="产品编号" prop="productNumber" :show-overflow-tooltip="true" />
						<el-table-column label="产品型号" prop="productModel" :show-overflow-tooltip="true" />
						<el-table-column label="军检状态" align="center" prop="militaryInspectionStatus"
							:show-overflow-tooltip="true" :formatter="getStatus"> </el-table-column>
					</el-table>
					<pagination :total="productTotal" :page.sync="queryProcuct.pageNum"
						:limit.sync="queryProcuct.pageSize" @pagination="getrepairProductList" />
				</div>
				<div class="userCenter">
					<div @click="setRight"><i class="el-icon-right"></i></div>
					<div @click="setLeft"><i class="el-icon-back"></i></div>
				</div>
				<div class="userRight">
					<el-table :data="selectProductList" height="488px" ref="rightTable"
						@selection-change="handleBackUser" border>
						<el-table-column type="selection" width="55" align="center" />
						<el-table-column type="index" width="55" align="center" label="序号" />
						<el-table-column label="产品名称" prop="productName" :show-overflow-tooltip="true" />
						<el-table-column label="产品编号" prop="productNumber" :show-overflow-tooltip="true" />
						<el-table-column label="产品型号" prop="productModel" :show-overflow-tooltip="true" />
						<el-table-column label="军检状态" align="center" prop="militaryInspectionStatus"
							:show-overflow-tooltip="true" :formatter="getStatus"> </el-table-column>
					</el-table>
				</div>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>

		<el-dialog :title="titles1" :visible.sync="recordsopen" width="1200px" append-to-body v-dialogDrag>
			<el-button @click="checks" :disabled="multipleRecords" type="primary"
				v-if="!writeShow && titles1 == '核验'">核验</el-button>
			<div style="height: 67vh; overflow-y: auto; margin-top: 10px">
				<el-table ref="writeTable" @mousedown.native="mousedownTable" @cell-mouse-enter="cell_mouse_enter"
					row-key="id" @cell-mouse-leave="cell_mouse_leave" @mouseup.native="mouseupTable"
					@mouseleave.native="mouseupTable" @row-click="row_clicks" v-loading="recordsloading"
					:data="recordsList" @selection-change="handleSelectionRecords" border>
					<el-table-column type="selection" width="55" align="center" />
					<el-table-column type="index" width="55" align="center" label="序号" />
					<el-table-column label="包装内容" prop="packagType" :show-overflow-tooltip="true"
						:formatter="getcontent" min-width="180" />
					<el-table-column label="记录" align="center" prop="packagRecord" :show-overflow-tooltip="true"
						min-width="200">
						<template slot-scope="scope">
							<el-select v-model="scope.row.packagRecord" v-if="scope.row.isdefault" clearable
								@blur="editData(scope.row)" @change="changeDatas(scope.row)"
								:disabled="!writeShow ? true : false">
								<el-option v-for="item in packagRecordList" :key="item.id" :value="item.name"
									:label="item.name"> </el-option>
							</el-select>
							<el-input style="width: 220px" v-else clearable="" v-model="scope.row.packagRecord"
								maxlength="50" @blur="editData(scope.row)"
								:disabled="!writeShow ? true : false"></el-input>
							<el-button size="mini" @click="clearData(scope.$index)" style="margin-left: 10px"
								v-if="writeShow">填写其他</el-button>
						</template>
					</el-table-column>
					<el-table-column label="操作者" align="center" prop="packagUserName" :show-overflow-tooltip="true"
						min-width="100">
						<template slot-scope="scope">
							<el-select v-model="scope.row.packagUserId" @change="selectData(scope.row, $event)"
								:disabled="!writeShow ? true : false">
								<el-option v-for="item in workLists" :key="item.userId" :value="item.userId"
									:label="item.nickName"></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column label="检验员名称" align="center" min-width="100" prop="checkoutUserName"
						v-if="!writeShow" :show-overflow-tooltip="true" :formatter="getStatus">
						<template slot-scope="scope">
							<el-input v-model="scope.row.checkoutUserName" disabled></el-input>
						</template>
					</el-table-column>
					<el-table-column label="检验员日期" align="center" min-width="100" prop="checkoutDate" v-if="!writeShow"
						:show-overflow-tooltip="true" :formatter="getStatus">
						<template slot-scope="scope">
							<el-input v-model="scope.row.checkoutDate" disabled></el-input>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="recordsopenSubmit">确 定</el-button>
				<el-button @click="recordsopen = false">取 消</el-button>
			</div>
		</el-dialog>

		<el-dialog title="修改" :visible.sync="edit" width="900px" append-to-body v-dialogDrag>
			<el-form ref="form" :model="form" label-width="68px">
				<el-form-item label="备注" prop="remark">
					<el-input type="textarea" v-model="form.remark" placeholder="请输入备注" maxlength="100" show-word-limit
						rows="3" />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitFormedit">确 定</el-button>
				<el-button @click="edit = false">取 消</el-button>
			</div>
		</el-dialog>

		<el-dialog title="发货检查" :visible.sync="checkedopen" width="900px" append-to-body v-dialogDrag>
			<el-form ref="formcheck" :model="formcheck" label-width="100px" :rules="rules">
				<el-row :gutter="20">
					<el-col :span="12">
						<el-form-item label="包装操作者" prop="packagUserId">
							<el-select v-model="formcheck.packagUserId" @change="selectpackagUser">
								<el-option v-for="item in workLists" :key="item.userId" :value="item.userId"
									:label="item.nickName"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="检验员" prop="checkoutUserId">
							<el-select v-model="formcheck.checkoutUserId" @change="selectcheckoutUser">
								<el-option v-for="item in userlist" :key="item.userId" :value="item.userId"
									:label="item.nickName"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div>
				<div class="onerow">
					<div>产品名称</div>
					<div><el-input style="width: 130px" v-model="formcheck.productName"></el-input></div>
					<div>产品型号</div>
					<div style="border-right: 1px solid"><el-input style="width: 130px"
							v-model="formcheck.productModel"></el-input></div>
				</div>
				<div class="onerow">
					<div style="border-top: none">产品数量</div>
					<div style="border-top: none"><el-input style="width: 130px"
							v-model="formcheck.productNumber"></el-input>
					</div>
					<div style="border-top: none">任务单编号</div>
					<div style="border-right: 1px solid; border-top: none"><el-input style="width: 130px"
							v-model="formcheck.repairNumber"></el-input></div>
				</div>
				<div class="onerow">
					<div style="border-top: none">封装数量</div>
					<div style="border-top: none"><el-input style="width: 130px"
							v-model="formcheck.boxOneQuantity"></el-input>箱
					</div>
					<div style="border-top: none"><el-input style="width: 50px"
							v-model="formcheck.boxTwoQuantity"></el-input>箱
						<el-input style="width: 60px" v-model="formcheck.pieceOneQuantity"></el-input>件
					</div>
					<div style="border-right: 1px solid; border-top: none"><el-input style="width: 130px"
							v-model="formcheck.pieceTwoQuantity"></el-input>件</div>
				</div>
			</div>
			<div style="height: 52vh; overflow-y: auto; margin-top: 10px">
				<el-table v-loading="checkedloading" :data="formcheck.tdeliverResultList" border>
					<!-- <el-table-column type="selection" width="55" align="center" /> -->
					<el-table-column type="index" width="55" align="center" label="序号" />
					<el-table-column label="检查内容" prop="deliverType" :show-overflow-tooltip="true"
						:formatter="getcontentcheck" min-width="180" />
					<el-table-column label="检查结果" align="center" prop="deliverResult" :show-overflow-tooltip="true"
						min-width="180">
						<template slot-scope="scope">
							<el-input v-model="scope.row.deliverResult" maxlength="50" show-word-limit></el-input>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="cacheFormChecked">暂 存</el-button>
				<el-button type="primary" @click="submitFormChecked">确 定</el-button>
				<el-button @click="checkedopen = false">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import CreateForm from "@/views/components/CreateForm"
import { mapGetters } from "vuex"
import searchStateMixin from '@/layout/mixin/searchStateMixin.js'   
import { getcolumn, allocatedList } from "@/api/selectList"
import { workerAccomplish, auditAccomplish, detailList1, userDown, getpackag, workerList, repairProductList, installDeliver, generatePackage, detailsEdits, detailsEdit, detailList, getdeliver, packagdelete, packagedit, packagList, listConfig, getConfig, delConfig, addConfig, updateConfig, refreshCache } from "@/api/packageRecords"
export default {
	name: "PackageRecords",
	dicts: ["army_state"],
	components: { CreateForm },mixins: [searchStateMixin],   
	computed: {
		...mapGetters(["sidebar"])
	},
	data() {
		return {
			// 列信息
			columns: [
				// { key: 0, label: `记录编号`, visible: true },
				{ key: 0, label: `记录名称`, visible: true },
				{ key: 1, label: `产品名称`, visible: true },
				// { key: 3, label: `供方`, visible: true },
				// { key: 4, label: `送检时间`, visible: true },
				{ key: 2, label: `产品编号`, visible: true },
				// { key: 6, label: `生产批次`, visible: true },
				{ key: 3, label: `产品型号`, visible: true },
				{ key: 4, label: `包装发货状态`, visible: true },
				{ key: 5, label: `备注`, visible: true }
			],
			isMousedownTables: false, //是否按下表格
			currentEnterRows: null, //当前移入的行数据
			isMousedownTable: false, //是否按下表格
			currentEnterRow: null, //当前移入的行数据
			packagRecordList: [
				{
					id: "0",
					name: "合格"
				},
				{
					id: "1",
					name: "/"
				}
			],
			BackSelectionProcuct: [],
			selectProductList: [],
			queryProcuct: {
				pageNum: 1,
				pageSize: 10,
				productModel: undefined,
				productNumber: undefined
			},
			productTotal: 0,
			titles1: "",
			eleTabTop: 0, //表格容器距浏览器顶部距离
			rules: {
				packagUserId: [{ required: true, message: "包装操作者不能为空", trigger: "blur" }],
				checkoutUserId: [{ required: true, message: "检验员不能为空", trigger: "blur" }]
			},
			userlist: [],
			formcheck: {},
			checkedopen: false,
			checkedloading: false,
			workLists: [],
			checkContentList: [
				{
					id: "1",
					name: "包装箱规格符合工艺规程要求"
				},
				{
					id: "2",
					name: "无损伤"
				},
				{
					id: "3",
					name: "内包装完整、无破损、无漏气"
				},
				{
					id: "4",
					name: "包装支座、垫层牢固无破损"
				},
				{
					id: "5",
					name: "证（章）齐全"
				},
				{
					id: "6",
					name: "签写规范"
				},
				{
					id: "7",
					name: "整洁、保护到位、无损坏"
				},
				{
					id: "8",
					name: "放入指定部位"
				},
				{
					id: "9",
					name: "按工艺要求附带"
				},
				{
					id: "10",
					name: "品种（类）齐全"
				},
				{
					id: "11",
					name: "规格正确"
				},
				{
					id: "12",
					name: "数量准确"
				},
				{
					id: "13",
					name: "无超期"
				},
				{
					id: "14",
					name: "单独包裹放入包装箱指定位置"
				},
				{
					id: "15",
					name: "数量符合要求"
				},
				{
					id: "16",
					name: "放入位置正确"
				},
				{
					id: "17",
					name: "确定箱内无多余物"
				},
				{
					id: "18",
					name: "牢固"
				}
			],
			contentList: [
				{
					id: "1",
					name: "裁制包装纸"
				},
				{
					id: "2",
					name: "裁制包装袋"
				},
				{
					id: "3",
					name: "干燥剂的烘烤和保管"
				},
				{
					id: "4",
					name: "产品外观检查与清洗"
				},
				{
					id: "5",
					name: "制作标签"
				},
				{
					id: "6",
					name: "核对标签 "
				},
				{
					id: "7",
					name: "装袋（包好的产品、干燥剂、指示纸、标签)"
				},
				{
					id: "8",
					name: "封口（包装袋不允许漏气）"
				},
				{
					id: "9",
					name: "装箱（产品、备件、履历本、说明书等）"
				},
				{
					id: "10",
					name: "封箱及铅封"
				},
				{
					id: "11",
					name: "开装箱单"
				},
				{
					id: "12",
					name: "提交"
				}
			],
			edit: false,
			recordsopen: false,
			recordsloading: false,
			recordsList: [],
			// 遮罩层
			loading: true,
			// 选中数组
			ids: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			multipleRecords: true,
			// 显示搜索条件
			showSearch: true,
			// 总条数
			total: 0,
			// 参数表格数据
			configList: [],
			// 弹出层标题
			title: "",
			// 是否显示弹出层
			open: false,
			// 查询参数
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				configName: undefined,
				configKey: undefined,
				configType: undefined,
				recordName: undefined
			},
			// 表单参数
			form: {},
			productList: [],
			productopen: false,
			productloading: false,
			productIds: [],
			recordIds: [],
			recordId: "",
			recordsSection: [],
			writeShow: true,
			preventBlur: true,
			newQuerys: {}
		}
	},
	created() {
		// this.getSize()
		this.getworkerList()
		this.getuserDown()
	},
	mounted() {
		// 滚动条的获取
		this.handleScrollx()
		window.addEventListener("scroll", this.handleScrollx, true)
	},
	watch: {
		"$route.query": {
			handler(newQuery, oldQuery) {
				if (newQuery.queryData) {
					if (Object.keys(newQuery.queryData).length === 0) {
						this.newQuerys = {}
						this.resetForm("queryForm")
						// this.getSize()
					} else {
						if (JSON.parse(newQuery.queryData).recordName) {
							this.newQuerys = {}
							this.queryProcuct.productModel = undefined
							this.queryProcuct.productNumber = undefined
							this.queryParams = { ...this.queryParams, ...JSON.parse(newQuery.queryData) }
						} else {
							this.newQuerys = {}
							this.queryParams.recordName = undefined
							this.newQuerys = JSON.parse(newQuery.queryData)
							this.queryProcuct = { ...this.queryProcuct, ...JSON.parse(newQuery.queryData) }
						}
						// this.getSize()
					}
				} this.getSize()
			},
			immediate: true, // 立即执行一次
			deep: true // 深度监听
		}
	},
	activated() {
		// this.getSize()
		//获取表格容器距页面头部的距离
		this.handleScrollx()
	},
	destroyed() {
		window.removeEventListener("scroll", this.handleScrollx, true)
	},
	methods: {
		getSize() {
			getcolumn({ pageName: "Pagination25" }).then(response => {
				this.queryParams.pageSize = response.data.length ? (response.data[0].limit ? response.data[0].limit : 10) : 10
				this.getList()
			})
		},
		changeTableData() {
			this.$nextTick(() => {
				this.$refs.table.doLayout()
			})
		},
		mousedownTables(event) {
			const target = event.target
			// 判断target的class属性确定是否点击在复选框上
			if (target.classList.contains("el-checkbox__inner")) {
				this.currentEnterRows && this.$refs.table.toggleRowSelection(this.currentEnterRows)
				this.isMousedownTables = true
			}
		},
		// 进入单元格
		cell_mouse_enters(row, column, cell, event) {
			this.isMousedownTables && this.$refs.table.toggleRowSelection(row)
			this.currentEnterRows = row
		},
		// 离开单元格
		cell_mouse_leaves(row, column, cell, event) {
			this.currentEnterRows = null
		},
		// 鼠标弹起或者离开表格
		mouseupTables(d) {
			this.isMousedownTables = false
		},

		// recordsSection
		// 表格按下
		mousedownTable(event) {
			const target = event.target
			// 判断target的class属性确定是否点击在复选框上
			if (target.classList.contains("el-checkbox__inner")) {
				this.currentEnterRow && this.$refs.writeTable.toggleRowSelection(this.currentEnterRow)
				this.isMousedownTable = true
			}
		},
		row_clicks(row, column, event) {
			this.$refs.writeTable.toggleRowSelection(row)
		},
		// 进入单元格
		cell_mouse_enter(row, column, cell, event) {
			this.isMousedownTable && this.$refs.writeTable.toggleRowSelection(row)
			this.currentEnterRow = row
		},
		// 离开单元格
		cell_mouse_leave(row, column, cell, event) {
			this.currentEnterRow = null
		},
		// 鼠标弹起或者离开表格
		mouseupTable(d) {
			this.isMousedownTable = false
		},
		clearData(index) {
			this.recordsList[index].isdefault = !this.recordsList[index].isdefault
		},
		/** 搜索按钮操作 */
		handleQueryUser() {
			this.queryProcuct.pageNum = 1
			  
			this.getrepairProductList()
		},
		/** 重置按钮操作 */
		resetQueryUser() {
			this.resetSelect()
			this.handleQueryUser()
		},
		// 去重
		removeSame1(arr) {
			let map = new Map()
			for (let item of arr) {
				// map.has()方法判断map中是否存在这个键
				// 不存在，则将键和值同时设置到map集合中，
				if (!map.has(item.id)) {
					map.set(item.id, item)
				}
			}
			// 返回map的值
			return [...map.values()]
		},
		setLeft() {
			this.BackSelectionProcuct.forEach(item => {
				this.selectProductList.forEach((items, index) => {
					if (item.id == items.id) {
						this.selectProductList.splice(index, 1)
					}
				})
			})
		},
		setRight() {
			this.selectProductList.push(...this.productIds)
			this.selectProductList = this.removeSame1(this.selectProductList)
			this.$refs.multipleTable.clearSelection()
		},
		handleBackUser(selection) {
			this.BackSelectionProcuct = selection
		},

		// 单击表格行
		row_click(row, column, event) {
			if (column && column.label == "操作") {
				return
			} else {
				this.$refs.table.toggleRowSelection(row)
			}
		},
		//获取表格容器距页面头部的距离
		handleScrollx() {
			this.eleTabTop = this.$refs.eleTab.getBoundingClientRect().top
		},
		cacheFormChecked() {
			console.log(this.formcheck, "formcheckformcheck")
			this.formcheck.momentFlag = 0
			installDeliver(this.formcheck).then(res => {
				this.$modal.msgSuccess("暂存成功")
				localStorage.setItem("todoMessage", "packageRecords2")
				this.checkedopen = false
				this.getList()
			})
		},
		submitFormChecked() {
			this.formcheck.momentFlag = 1
			let flag = true
			this.formcheck.tdeliverResultList.forEach(item => {
				if (!item.deliverResult) {
					flag = false
				}
			})
			this.$refs["formcheck"].validate(valid => {
				if (valid) {
					if (flag && this.formcheck.boxOneQuantity && this.formcheck.boxTwoQuantity && this.formcheck.pieceOneQuantity && this.formcheck.pieceTwoQuantity) {
						installDeliver(this.formcheck).then(response => {
							this.$modal.msgSuccess("设置成功")
							this.checkedopen = false
							localStorage.setItem("todoMessage", "packageRecords1")
							this.getList()
						})
					} else {
						this.$modal.msgError("请先将数据填写完整")
					}
				}
			})
		},
		selectpackagUser(e) {
			this.workLists.forEach(item => {
				if (item.userId == e) {
					this.formcheck.packagUserName = item.nickName
				}
			})
		},
		selectcheckoutUser(e) {
			this.userlist.forEach(item => {
				if (item.userId == e) {
					this.formcheck.checkoutUserName = item.nickName
				}
			})
		},
		getuserDown() {
			allocatedList().then(res => {
				this.userlist = res.rows
			})
		},
		handleChecked(row) {
			this.checkedloading = true
			getdeliver(row.id).then(res => {
				this.checkedopen = true
				this.formcheck = res.data
				this.formcheck.productName = row.productName
				this.formcheck.productNumber = row.productNumber
				this.formcheck.productModel = row.productModel
				this.formcheck.repairNumber = row.repairNumber
				this.checkedloading = false
			})
		},
		getCurrentDate() {
			let now = new Date()
			let year = now.getFullYear()
			let month = now.getMonth() + 1
			let day = now.getDate()
			return year + "-" + month + "-" + day
		},
		recordsopenSubmit() {
			// 填写
			if (this.writeShow) {
				workerAccomplish(this.recordId).then(res => {
					this.$modal.msgSuccess(`${this.titles1}成功`)
					this.recordsopen = false
					localStorage.setItem("todoMessage", "packages2")
				})
			} else {
				auditAccomplish(this.recordId).then(res => {
					this.$modal.msgSuccess("核验成功")
					this.recordsopen = false
					localStorage.setItem("todoMessage", "packages3")
				})
			}
		},
		checks() {
			let flag = true
			if (flag) {
				detailsEdits({
					ids: this.recordIds,
					checkoutDate: this.getCurrentDate()
				}).then(res => {
					this.$modal.msgSuccess("核验成功")
					// this.recordsopen = false
					this.getdetailList()
					this.getList()
				})
			} else {
				this.$modal.msgError("请先将数据填写完整")
			}
		},
		selectData(row, e) {
			this.workLists.forEach(item => {
				if (item.userId == e) {
					row.packagUserName = item.nickName
					detailsEdit(row).then(res => {
						this.$modal.msgSuccess("修改成功")
					})
				}
			})
		},
		setData(row) {
			let packagRecord = row.packagRecord
			let flag1 = this.recordIds.includes(row.id)
			if (this.recordsSection.length && flag1) {
				this.recordsSection.forEach((item, index) => {
					this.recordsSection[index].packagRecord = packagRecord
					this.recordsList.forEach((items, index1) => {
						if (item.id == items.id) {
							this.recordsList[index1].packagRecord = packagRecord
						}
					})
					detailsEdit(item).then(res => {
						if (index == this.recordsSection.length - 1) {
							// if(!this.preventBlur){
							//   this.$modal.msgSuccess("修改成功")
							// }
						}
					})
				})
			} else {
				detailsEdit(row).then(res => {
					// this.$modal.msgSuccess("修改成功")
				})
			}
			// 假设处理完毕后，延迟重置标志位
			// setTimeout(() => {
			// this.preventBlur = false // 重置标志位为 false
			// }, 0) // 使用 setTimeout 来确保异步执行
		},
		changeDatas(row) {
			this.preventBlur = true
			this.setData(row)
		},
		editData(row) {
			this.preventBlur = false
			// if (!this.preventBlur) {
			this.setData(row)
			// }
			// this.changeDatas(row)
		},
		handleSelectionRecords(selection) {
			this.recordsSection = selection
			this.recordIds = selection.map(item => item.id)
			this.multipleRecords = !selection.length
		},
		handleWrite(row) {
			this.recordId = row.id
			this.recordsopen = true
			this.writeShow = true
			this.titles1 = "填写"
			this.getdetailList()
		},
		handleReocrds1(row) {
			this.writeShow = false
			this.recordId = row.id
			this.titles1 = "详情"
			this.recordsopen = true
			this.getdetailList1()
		},
		handleReocrds(row) {
			this.writeShow = false
			this.recordId = row.id
			this.titles1 = "核验"
			this.recordsopen = true
			this.getdetailList1()
		},
		getdetailList1() {
			detailList1({ packagId: this.recordId }).then(res => {
				res.rows.forEach(item => {
					item.isdefault = true
				})
				this.recordsList = res.rows
			})
		},
		getdetailList() {
			detailList({ packagId: this.recordId }).then(res => {
				res.rows.forEach(item => {
					item.isdefault = true
				})
				this.recordsList = res.rows
			})
		},
		getworkerList() {
			workerList().then(res => {
				this.workLists = res.rows
			})
		},
		submitFormedit() {
			packagedit(this.form).then(res => {
				this.$modal.msgSuccess("修改成功")
				this.edit = false
				this.getList()
			})
		},
		getcontentcheck(row, column, cellValue, index) {
			let labels = ""
			this.checkContentList.forEach(element => {
				if (element.id == row.deliverType) {
					labels = element.name
				}
			})
			return labels
		},
		getcontent(row, column, cellValue, index) {
			let labels = ""
			this.contentList.forEach(element => {
				if (element.id == row.packagType) {
					labels = element.name
				}
			})
			return labels
		},
		getStatus(row, column, cellValue, index) {
			let labels = ""
			this.dict.type.army_state.forEach(element => {
				if (element.value == row.militaryInspectionStatus) {
					labels = element.label
				}
			})
			return labels
		},
		handleSelectionProduct(selection) {
			this.productIds = selection
		},
		/** 查询参数列表 */
		getList() {
			this.loading = true
			packagList(this.queryParams).then(response => {
				this.configList = response.rows
				this.total = response.total
				this.loading = false
			})
		},
		// 取消按钮
		cancel() {
			this.$refs.multipleTable.clearSelection()
			this.open = false
			this.productIds = []
			this.selectProductList = []
			this.productList = []
		},
		// 表单重置
		reset() {
			this.form = {
				remark: undefined,
				recordName: undefined
			}
			this.resetForm("form")
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1
			this.saveSearchState()  
			this.getList()
		},
		/** 重置按钮操作 */
		resetQuery() {
			this.resetForm("queryForm")
			this.queryParams.recordName = undefined
			this.clearSearchCache() 
			this.handleQuery()
		},
		getrepairProductList() {
			this.productloading = true
			repairProductList(this.queryProcuct).then(res => {
				this.productList = res.rows
				this.productloading = false
				this.productTotal = res.total
			})
		},
		/** 新增按钮操作 */
		handleAdd() {
			if (Object.keys(this.newQuerys).length === 0) {
				this.resetSelect()
			} else {
				this.queryProcuct = { ...this.queryProcuct, ...this.newQuerys }
			}
			this.selectProductList = []
			this.productList = []
			this.productIds = []
			this.getrepairProductList()
			this.open = true
			this.title = "添加参数"
		},
		resetSelect() {
			this.queryProcuct = {
				pageNum: 1,
				pageSize: 10,
				productModel: undefined,
				productNumber: undefined
			}
			this.resetForm("queryProcuct")
		},
		// 多选框选中数据
		handleSelectionChange(selection) {
			this.ids = selection.map(item => item.id)
			this.single = selection.length != 1
			this.multiple = !selection.length
		},
		/** 修改按钮操作 */
		handleUpdate(row) {
			this.recordId = row.id
			this.recordsopen = true
			this.writeShow = true
			this.titles1 = "修改"
			this.getdetailList()

			// this.reset()
			// getpackag(row.id).then(response => {
			// 	this.form = response.data
			// 	this.edit = true
			// 	this.title = "修改"
			// })
		},
		/** 提交按钮 */
		submitForm() {
			if (this.selectProductList.length == 0) {
				this.$modal.msgWarning("请选择产品")
				return
			}

			let ids = []
			this.selectProductList.forEach(item => {
				ids.push(item.id)
			})
			generatePackage(ids).then(response => {
				this.$modal.msgSuccess("新增成功")
				localStorage.setItem("todoMessage", "packages1")
				this.open = false
				this.getList()
			})
		},
		/** 删除按钮操作 */
		handleDelete(row) {
			const configIds = row.id || this.ids
			this.$modal
				.confirm("是否确认删除包装记录数据项？")
				.then(function () {
					return packagdelete(configIds)
				})
				.then(() => {
					this.getList()
					this.$modal.msgSuccess("删除成功")
				})
				.catch(() => { })
		},
		/** 导出按钮操作 */
		handleExport() {
			this.download(
				"system/config/export",
				{
					...this.queryParams
				},
				`config_${new Date().getTime()}.xlsx`
			)
		}
	}
}
</script>
<style lang="scss" scoped>
.userDialog {
	display: flex;
	justify-content: space-between;
	align-items: center;

	.userLeft {
		width: 50%;
	}

	.userRight {
		width: 46%;
	}

	.userRight {
		padding-bottom: 5px;
	}

	.userCenter {
		margin: 0 10px;

		>div:first-child {
			margin-bottom: 50px;
		}

		.el-icon-right,
		.el-icon-back {
			font-size: 30px !important;
		}
	}
}

::v-deep .el-table__fixed-header-wrapper .fixed-width {
	width: 240px !important;
}

.onerow {
	display: flex;
	align-items: center;

	::v-deep input[type="text"] {
		border: none;
		outline: none;
	}

	>div {
		width: 220px;
		border: 1px solid;
		height: 38px;
		line-height: 36px;
		text-align: center;
		border-right: none;
		// border-top: none;
	}
}
</style>
